﻿using System;
using System.Xml;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Exepack;
using System.Reflection;
using Process = System.Diagnostics.Process;

namespace ExepackTests
{
	/// <summary>
	/// Test suite for AssemblyInformation
	/// </summary>
	[TestClass]
	public class AssemblyInformationTest
	{
		#region MS-Generated Code

		public AssemblyInformationTest()
		{
		}

		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		//
		// You can use the following additional attributes as you write your tests:
		//
		// Use ClassInitialize to run code before running the first test in the class
		// [ClassInitialize()]
		// public static void MyClassInitialize(TestContext testContext) { }
		//
		// Use ClassCleanup to run code after all tests in a class have run
		// [ClassCleanup()]
		// public static void MyClassCleanup() { }
		//
		// Use TestInitialize to run code before running each test 
		// [TestInitialize()]
		// public void MyTestInitialize() { }
		//
		// Use TestCleanup to run code after each test has run
		// [TestCleanup()]
		// public void MyTestCleanup() { }
		//
		#endregion

		#endregion

		[TestMethod]
		public void AssemblyInformation_StringAndIntAssembliesAreSame()
		{
			// mscorlib.dll == mscorlib.dll
			AssemblyInformation asm1 = new AssemblyInformation(typeof(string));
			AssemblyInformation asm2 = new AssemblyInformation(typeof(int));
			Assert.IsTrue(asm1.Equals(asm2));
		}

		[TestMethod]
		public void AssemblyInformation_CachedAssembliesTest()
		{
			// mscorlib.dll is cached
			AssemblyInformation asm1 = new AssemblyInformation(typeof(string));
			AssemblyInformation asm2 = new AssemblyInformation(typeof(int));
			Assert.IsTrue(asm1.Asm == asm2.Asm);
		}

		[TestMethod]
		public void AssemblyInformation_StringAndProcessAssembliesAreDifferent()
		{
			// mscorlib.dll != System.dll
			AssemblyInformation asm1 = new AssemblyInformation(typeof(string));
			AssemblyInformation asm2 = new AssemblyInformation(typeof(Process));
			Assert.IsFalse(asm1.Equals(asm2));
		}

		[TestMethod]
		public void AssemblyInformation_SystemXmlReferencesTest()
		{
			// System.Xml.dll has 4 references
			AssemblyInformation asm = new AssemblyInformation(typeof(XmlDocument));
			Assert.IsTrue(asm.References.Count() == 4);
		}

		[TestMethod]
		public void AssemblyInformation_SystemXmlAllReferencesTest()
		{
			// System.Xml.dll has 5 recursive references
			AssemblyInformation asm = new AssemblyInformation(typeof(XmlDocument));
			Assert.IsTrue(asm.AllReferences.Count == 5);
		}

		[TestMethod]
		public void AssemblyInformation_SystemXmlIsSystemAssembly()
		{ 
			// System.Xml.dll is a system assembly
			AssemblyInformation asm = new AssemblyInformation(typeof(XmlDocument));
			Assert.IsTrue(asm.IsSystemAssembly);
		}

		[TestMethod]
		public void AssemblyInformation_CurrentAssemblyIsNonSystem()
		{
			// this assembly is not a system assembly
			AssemblyInformation asm = new AssemblyInformation(typeof(AssemblyInformationTest).Assembly);
			Assert.IsFalse(asm.IsSystemAssembly);
		}

		[TestMethod]
		public void AssemblyInformation_CurrentAssemblyIsILOnly()
		{
			// this assembly is not a system assembly
			AssemblyInformation asm = new AssemblyInformation(typeof(AssemblyInformationTest).Assembly);
			Assert.IsTrue(asm.IsILOnly);
		}
	}
}
